﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Web.UI.MobileControls;
using System.Collections.Generic;

namespace YXShop.Web.membercenter.shop.shop_administer
{
    public partial class shop_leaveword_list : System.Web.UI.Page
    {
        YXShop.BLL.Accessories.Leaveword wordBll = new YXShop.BLL.Accessories.Leaveword();
        protected void Page_Load(object sender, EventArgs e)
        {
            if(!IsPostBack)
            {
                if (ChangeHope.WebPage.PageRequest.GetFormString("Option") != string.Empty && ChangeHope.WebPage.PageRequest.GetFormString("id") != "")
                {
                    string types = Request["Option"].Trim();
                    string id = ChangeHope.WebPage.PageRequest.GetFormString("id");
                    if (types == "del")
                    {
                        wordBll.DeleteById(Convert.ToInt32(id));
                    }
                    if (types == "delAll")
                    {
                        wordBll.Delete(id);
                    }
                    Response.End();
                    return;
                }
                this.litlist.Text = GetList();
            }
        }

        private string GetList()
        {
            ChangeHope.WebPage.Table table = new ChangeHope.WebPage.Table();
            ChangeHope.DataBase.DataByPage dataPage = new ChangeHope.DataBase.DataByPage();
            if (Session["MemberID"] != null)
            {
                YXShop.BLL.Shop.Shop shopBll = new YXShop.BLL.Shop.Shop();
                List< YXShop.Model.Shop.Shop> shopList= shopBll.GetListShopByWhere(" uid=" + Session["MemberID"].ToString());
                if(shopList!=null)
                {
                    dataPage = wordBll.GetList(" [order by] adddate DESC", 20, " and storeid=" +shopList[0].Sid.ToString());
                }
            }
            table.AddHeadCol("", "<input id=\"chall\" type=\"checkbox\" onclick=\"SelectAll(chall)\" />全选");
            table.AddHeadCol("","留言主题");
            table.AddHeadCol("","留言者");
            table.AddHeadCol("","留言时间");
            table.AddHeadCol("","是否回复");
            table.AddHeadCol("","操作");
            table.AddRow();
            if(dataPage.DataReader!=null)
            {
                while(dataPage.DataReader.Read())
                {
                    table.AddCol("<input id=\"cbTm\"  type=\"checkbox\" value=\"" + dataPage.DataReader["id"].ToString() + "\" />");
                    table.AddCol(dataPage.DataReader["title"].ToString());
                    table.AddCol(dataPage.DataReader["username"] == null ? "游客" : dataPage.DataReader["username"].ToString());
                    table.AddCol(dataPage.DataReader["adddate"].ToString());
                    table.AddCol(dataPage.DataReader["isreply"].ToString()=="0"?"未回复":"已回复");
                    string url = YXShop.TemplateAction.Common.UrlStr("shop_leaveword_edit", "leaveId="+dataPage.DataReader["id"].ToString(), "membercenter/shop/shop_administer/");
                    table.AddCol("<a href=\""+url+"\">查看/回复</a>&nbsp;<a href=\"#\" onclick='Del("+dataPage.DataReader["id"]+")'>删除</a>");
                    table.AddRow();
                }
            }
            string view = table.GetTable() + dataPage.ReceptionToolBar;
            dataPage.Dispose();
            dataPage = null;
            return view;
        }

        protected void linkSarch_Click(object sender, EventArgs e)
        {
            this.litlist.Text = GetList();
        }
    }
}
